package com.icode.core.shared.usertype;

import org.hibernate.HibernateException;
import org.hibernate.usertype.EnhancedUserType;

import java.io.Serializable;

/**
 * User: alexz
 * Date: 15-1-20
 * Time: 下午5:06
 */
public abstract class AbstractHibernateUserType implements EnhancedUserType, Serializable {

    @Override
    public String objectToSQLString(Object value) {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

    @Override
    public String toXMLString(Object value) {
        return value.toString();
    }

    @Override
    public Object fromXMLString(String xmlValue) {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

    @Override
    public boolean equals(Object x, Object y) throws HibernateException {
        if (x == y) {
            return true;
        }
        if (x == null || y == null) {
            return false;
        }
        return x.equals(y);
    }

    @Override
    public int hashCode(Object x) throws HibernateException {
        return x.hashCode();
    }

    @Override
    public Object deepCopy(Object value) throws HibernateException {
        return value;
    }

    @Override
    public boolean isMutable() {
        return false;
    }

    @Override
    public Serializable disassemble(Object value) throws HibernateException {
        return (Serializable) value;
    }

    @Override
    public Object assemble(Serializable cached, Object owner) throws HibernateException {
        return cached;
    }

    @Override
    public Object replace(Object original, Object target, Object owner) throws HibernateException {
        return owner;
    }
}
